﻿using InvestmentIntelligence.DbModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace InvestmentIntelligence.Data.Repository
{
    public interface IFundBookUpdatableRepository : IFundBookRepository
    {
        /// <summary>
        ///     Add new fund or fundbook
        /// </summary>
        /// <param name="fund"></param>
        /// <returns></returns>
        int AddFund(FundBookEntity fund);

        /// <summary>
        ///     Add new fund or fundbook
        /// </summary>
        /// <param name="funds"></param>
        /// <returns></returns>
        void AddFunds(List<FundBookEntity> funds);

        /// <summary>
        ///     Attach fund to analysis group
        /// </summary>
        void AddFundBookToAnalysisGroup(int groupiId, int fundId);

        /// <summary>
        ///     Remove fund from analysis group
        /// </summary>
        /// <param name="groupiId"></param>
        /// <param name="fundId"></param>
        void RemoveFundBookFromAnalysisGroup(int groupiId, int fundId);
        
        /// <summary>
        ///     Update existing fundbookentity
        /// </summary>
        /// <param name="book">item to update</param>
        /// <returns></returns>
        void Update(FundBookEntity book);

        void UpdateByOriginalId(FundBookEntity book);
    }

    public interface IFundBookRepository
    {
        /// <summary>
        ///     Return list of funds and fundbooks
        /// </summary>
        /// <returns></returns>
        List<T> GetListFunds<T>(Func<IQueryable<FundBookEntity>, IEnumerable<T>> f);

        /// <summary>
        ///     Return list of funds with fundbooks
        /// </summary>
        /// <returns></returns>
        List<T> GetListFundsWithBooks<T>(Func<IQueryable<FundBookEntity>, IEnumerable<T>> f);
        
        /// <summary>
        /// Get book by id
        /// </summary>
        /// <param name="bookId"></param>
        /// <returns></returns>
        FundBookEntity Get(int bookId);
        
        /// <summary>
        /// Get book by id
        /// </summary>
        /// <param name="bookId"></param>
        /// <returns></returns>
        FundBookEntity Get(string bookId);

        /// <summary>
        ///     get fund with fundbook by id
        /// </summary>
        /// <param name="fundId"></param>
        /// <returns></returns>
        FundBookEntity GetFundWithFundBooks(int fundId);


        /// <summary>
        /// Gets all funds/books ids.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="f">The f.</param>
        /// <returns></returns>
        List<T> GetAllActiveIds<T>(Func<IQueryable<int>, IEnumerable<T>> f);

        List<T> GetList<T>(Func<IQueryable<FundBookEntity>, IEnumerable<T>> func);

        void UpdateHasOpenPosition(int id);
    }
}